<?php

namespace zhtfrontend\models\datas;

use Yii;
use yii\helpers\ArrayHelper;
use common\components\behaviors\UpdateCacheBehavior;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use common\components\extenders\MenuManage;

/**
 * This is the model class for table "{{%classroom}}".
 *
 * @property integer $id
 * @property string $name
 * @property string $room_number
 * @property integer $max_count
 * @property integer $mechanic_id
 * @property double $area
 * @property string $info
 * @property integer $state
 * @property integer $user_id
 * @property integer $created_at
 */
class AuthItem extends \zhtfrontend\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%auth_item}}';
    }




    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'created_at', 'updated_at', 'menu_id'], 'integer'],
            [['name', 'description','rule_name','data'], 'string'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'name' => Yii::t('zhtfrontend', '名称'),
            'type' => Yii::t('zhtfrontend', '权限类型'),
            'description' => Yii::t('zhtfrontend', '权限描述'),
            'rule_name' => Yii::t('zhtfrontend', '权限名称'),
            'data' => Yii::t('zhtfrontend', '数据'),
            'created_at' => Yii::t('zhtfrontend', '创建时间'),
            'updated_at' => Yii::t('zhtfrontend', '修改时间'),
            'menu_id' => Yii::t('zhtfrontend', '关联菜单id'),
        ];
    }

    public function extraFields()
    {
        return [
            'operate' => function () {
                return (new MenuManage(MenuManage::RECORD_ITEM_TOOLBAR, $this->attributes))->create();
            },
        ];
    }

    public function fields()
    {
        $fields = parent::fields();
        $fields['created_at'] = function () {
            return \Yii::$app->formatter->asDatetime($this->created_at);
        };
        $fields['updated_at'] = function () {
            return \Yii::$app->formatter->asDatetime($this->updated_at);
        };
        return $fields;
    }
}
